package com.qf.admin.service.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.common.domain.admin.vo.OptionsVO;
import com.qf.common.domain.admin.vo.RolePageVO;
import com.qf.admin.service.system.SysRoleMenuService;
import com.qf.admin.service.system.SysRoleService;
import com.qf.common.domain.admin.dos.SysRole;
import com.qf.common.domain.admin.dos.SysRoleMenu;
import com.qf.common.domain.admin.mapper.SysRoleMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author sin
* @description 针对表【sys_role(角色表)】的数据库操作Service实现
* @createDate 2024-10-12 16:52:40
*/
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole>
    implements SysRoleService{

    @Resource
    private SysRoleMapper roleMapper;

    @Resource
    private SysRoleMenuService roleMenuService;


    @Override
    public List<OptionsVO> getAllRoleList() {
        return roleMapper.getAllRoleList();
    }

    @Override
    public List<RolePageVO> getRolePage(String name, Integer status, String code) {
        return roleMapper.getRolePage(name,status,code);
    }

    @Override
    public List<Long> getRoleMenuByRoleId(Long roleId) {
        return roleMapper.getMenuByRoleId(roleId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateRoleMenu(Long roleId, List<Long> menuIds) {
        roleMenuService.remove(new QueryWrapper<SysRoleMenu>().eq("role_id",roleId));
        List<SysRoleMenu> roleMenus = menuIds.stream().map(menuId -> new SysRoleMenu(roleId, menuId)).collect(Collectors.toList());
        return roleMenuService.saveBatch(roleMenus);
    }
}









